package com.itheima.sfbx.insurance.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.itheima.sfbx.framework.commons.basic.ResponseResult;
import com.itheima.sfbx.framework.commons.utils.ResponseResultBuild;
import com.itheima.sfbx.insurance.dto.SafeguardVO;
import com.itheima.sfbx.insurance.service.ISafeguardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("保障项管理")
@RestController
@RequestMapping("/safeguard")
public class SafeguardController {

    @Autowired
    private ISafeguardService safeguardService;

    /**
     * 根据查询条件分页查询保障项
     * @param safeguardVO 查询条件
     * @param pageNum 页号
     * @param pageSize 页大小
     * @return 返回结果
     */
    @ApiOperation(value = "根据条件分页查询保障项",notes="根据条件分页查询保障项")
    //指定swagger的方法参数有哪些,以后在swagger的文档上看得到这些形参的具体属性
    @ApiImplicitParams({
        @ApiImplicitParam(name = "safeguardVO",value = "查询条件",required = true,dataType = "SafeguardVO"),
        @ApiImplicitParam(name = "pageNum",value = "页号",required = true,dataType = "Integer"),
        @ApiImplicitParam(name = "pageSize",value = "页大小",required = true,dataType = "Integer")
    })
    // ApiOperationSupport指定哪些参数要显示在swagger文档中
    @ApiOperationSupport(includeParameters = {"safeguardVO.safeguardKey","safeguardVO.safeguardKeyName","safeguardVO.safeguardVal","safeguardVO.safeguardType","safeguardVO.dataState","safeguardVO.sortNo","safeguardVO.remake","safeguardVO.checkedIds"})
    @PostMapping("/page/{pageNum}/{pageSize}")
    public ResponseResult<Page<SafeguardVO>> findSafeguardVoPage(@RequestBody SafeguardVO safeguardVO,
                                                                @PathVariable("pageNum")Integer pageNum,
                                                                @PathVariable("pageSize")Integer pageSize){
        Page<SafeguardVO> page = safeguardService.findPage(safeguardVO, pageNum, pageSize);
        return ResponseResultBuild.successBuild(page);
    }

    /**
     * 新建 保障项
     * @param safeguardVO 保障项
     * @return 携带有id的保障项
     */
    @ApiOperation(value = "新增保障项",notes="新增保障项")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "safeguardVO",value = "保障项",required = true,dataType = "SafeguardVO")
    })
    @ApiOperationSupport(includeParameters = {"safeguardVO.safeguardKey","safeguardVO.safeguardKeyName","safeguardVO.safeguardVal","safeguardVO.safeguardType","safeguardVO.dataState","safeguardVO.sortNo","safeguardVO.remake"})
    @PutMapping
    public ResponseResult<SafeguardVO> createSafeguard(@RequestBody SafeguardVO safeguardVO){
        SafeguardVO result = safeguardService.save(safeguardVO);
        return ResponseResultBuild.successBuild(result);
    }

    /**
     * 修改 保障项
     * @param safeguardVO 修改的保障项对象
     * @return 修改成功
     */
    @ApiOperation(value = "修改保障项",notes="修改保障项")
    @ApiImplicitParams(
        @ApiImplicitParam(name = "safeguardVO",value = "保障项",required = true,dataType = "SafeguardVO")
    )
    @ApiOperationSupport(includeParameters = {"safeguardVO.id","safeguardVO.safeguardKey","safeguardVO.safeguardKeyName","safeguardVO.safeguardVal","safeguardVO.safeguardType","safeguardVO.dataState","safeguardVO.sortNo","safeguardVO.remake"})
    @PatchMapping
    public ResponseResult<Boolean> updateSafeguard(@RequestBody SafeguardVO safeguardVO){
        Boolean result = safeguardService.update(safeguardVO);
        return ResponseResultBuild.successBuild(result);
    }


    /**
     * 删除 保障项
     * @param safeguardVO 删除的保障项id集合
     * @return 删除成功
     */
    @ApiOperation(value = "删除保障项",notes="删除保障项")
    @ApiImplicitParams(
        @ApiImplicitParam(name = "safeguardVO",value = "保障项",required = true,dataType = "SafeguardVO")
    )
    @ApiOperationSupport(includeParameters = {"safeguardVO.checkedIds"})
    @DeleteMapping
    public ResponseResult<Boolean> deleteSafeguard(@RequestBody SafeguardVO safeguardVO){
        Boolean result = safeguardService.delete(safeguardVO.getCheckedIds());
        return ResponseResultBuild.successBuild(result);
    }

    /**
     * 多条件查询保障项列表
     * @param safeguardVO 保障项VO对象
     * @return List<SafeguardVO>
     */

    @PostMapping("list")
    @ApiOperation(value = "多条件查询保障项列表",notes="多条件查询保障项列表")
    @ApiImplicitParams(
        @ApiImplicitParam(name = "safeguardVO",value = "保障项",required = true,dataType = "SafeguardVO")
    )
    @ApiOperationSupport(includeParameters = {"safeguardVO.safeguardKey","safeguardVO.safeguardKeyName","safeguardVO.safeguardVal","safeguardVO.safeguardType","safeguardVO.dataState","safeguardVO.sortNo","safeguardVO.remake"})
    public ResponseResult<List<SafeguardVO>> safeguardList(@RequestBody SafeguardVO safeguardVO){
        List<SafeguardVO> safeguardVOList = safeguardService.findList(safeguardVO);
        return ResponseResultBuild.successBuild(safeguardVOList);
    }

}
